<?php
// +----------------------------------------------------------------------
// | 功能说明"
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2030 http://www.jmzh1688.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: lxl
// | jmzhfsauto
// +----------------------------------------------------------------------
namespace app\admin\model;
use Think\Db;
use think\Model;

class TrackdetailesModel extends Model{
    protected $name = 'track_data';
    protected $autoWriteTimestamp = true;//时间自动更新 create_time ,update_time

    public function edit($param){
        try{
            $result =  $this->update($param);
            if(false === $result){
                return msg(-1, '', $this->getError());
            }else{
                return msg(1,url('TrackDetails/index'), '修改成功');
            }
        }catch(PDOException $e){
            return msg(-2, '', $e->getMessage());
        }
    }


    public function add($param){
        try{
            $param['isdelete'] = 0;
            $result =  $this->save($param);
            if(false === $result){
                return msg(-1, '', $this->getError());
            }else{
                return msg(1,url('TrackDetails/index'), '添加成功');
            }
        }catch(PDOException $e){
            return msg(-2, '', $e->getMessage());
        }
    }
    public function getById($id){
        return $this->where('id', $id)->find();
    }

    public function delById($id){
        try{
            $this->where('id', $id)->update(['isdelete'=>'1']);
            return msg(1, '', '删除成功');
        }catch( PDOException $e){
            return msg(-1, '', $e->getMessage());
        }
    }

    public function getActionWhere($where){
        return $this->where($where)->find();
    }


    public function getListbyRoleId($roleid){
        $para['isdelete']=0;
        $role=Db::name('sys_role')->where('id',$roleid)->find();
        if($roleid==0||$roleid==1){
            $result =  $this->where($para)->order('ordernum asc')->select();
            return $result;
        }
        if(!empty($role)){
            $menut=  config('database.prefix')."sys_role";

            $idstr=" FIND_IN_SET(id , (select menulist from ".$menut." where id=".$roleid."))";
            $result =  $this->where($para)->where($idstr)->order('ordernum asc')->select();

            $t=$this->getLastSql();
            return $result;

        }
        return null;
    }


}
